
export class SubProductBean {
  id : string
  constructor(id : string) {
    this.id = id
  }
}

export class ProductBean {
  id : string
  name : string
  price : number
  img : string
  totalStock : number //有效库存减锁定库存得来
  valid_stock : number
  state : number
  sort ?: number
  subList : Array<SubProductBean> = new Array<SubProductBean>()
  constructor(id : string,
    name : string,
    price : number,
    img : string,
    stock : number,
    valid_stock : number,
    state : number,
    sort ?: number) {
    this.id = id
    this.name = name
    this.price = price
    this.img = img
    this.totalStock = stock
    this.valid_stock = valid_stock
    this.state = state
    this.sort = sort
    // this.setDisplayPrice()
    this.setError()
  }

  isError : boolean = false

  setError() {
    if (this.valid_stock <= 0 || this.state != 0) {
      this.isError = true
    }
  }
  // displayPrice ?: string
  // private setDisplayPrice() : void {
  //   this.displayPrice = '￥' + (this.price / 100).toFixed(2)
  // }
}

export class CartProduct {
  count : number = 0
  max : number = 0
  recordCount : number = 0
  product : ProductBean

  constructor(max : number, p : ProductBean) {
    this.max = max
    this.product = p
  }

  plus() : boolean {
    let v = this.count + 1
    if (v > this.max) {
      this.count = this.max
      this.setRecord()
      return false
    } else {
      this.count = v
      this.setRecord()
      return true
    }
  }

  minus() {
    this.count -= 1
    if (this.count < 0) {
      this.count = 0
      this.setRecord()
    }
  }

  setRecord() {
    this.recordCount = this.count
  }

  resetRecord() {
    this.count = this.recordCount
  }
}


export class CreateOrderBean {
  device_id : string
  coupon : number
  items : Array<CreateOrderItem>
  constructor(device_id : string, coupon : number, items : Array<CreateOrderItem>) {
    this.device_id = device_id
    this.items = items
    this.coupon = coupon
  }
}

export class CreateOrderItem {
  product_id : string
  quantity : number
  constructor(product_id : string, quantity : number) {
    this.product_id = product_id
    this.quantity = quantity
  }
}

export class UserInfo {
  object_id : string
  header : string
  name : string
  nickname : string
  real_name : string
  weixin_number : string
  address : string
  phone : string
  email : string

  constructor(
    object_id : string,
    header : string,
    name : string,
    nickname : string,
    real_name : string,
    weixin_number : string,
    address : string,
    phone : string,
    email : string
  ) {
    this.object_id = object_id
    this.header = header
    this.name = name
    this.nickname = nickname
    this.real_name = real_name
    this.weixin_number = weixin_number
    this.address = address
    this.phone = phone
    this.email = email

  }

}

export class DataInfo<T> {
  page : number
  per_page : number
  total : number
  list : Array<T>
  constructor(
    page : number,
    per_page : number,
    total : number,
    list : Array<T>
  ) {
    this.page = page
    this.per_page = per_page
    this.total = total
    this.list = list
    this.pages = total / per_page
  }
  pages : number
}


export class CouponBean {
  coupon : Coupon
  coupon_batch : CouponBatch
  coupon_ticket : CouponTicket
  constructor(
    coupon : Coupon,
    coupon_batch : CouponBatch,
    coupon_ticket : CouponTicket
  ) {
    this.coupon = coupon
    this.coupon_batch = coupon_batch
    this.coupon_ticket = coupon_ticket
    this.couponHintName()
    this.setLimitHint()
    this.setValue()
    this.setDiscountValueHint()
  }

  hintName : string
  couponHintName() {
    if (this.coupon.mode == 0) {//0是满减，1是折扣
      this.hintName = "限时满减红包"
    } else if (this.coupon.mode == 1) {
      this.hintName = "限时折扣红包"
    } else {
      this.hintName = "优惠券"
    }

  }

  limitHint : string
  setLimitHint() {
    this.limitHint = `满${this.coupon.threshold / 100}可用`
  }

  valueHint : number = 0
  setValue() {
    this.valueHint = this.coupon.reduce / 100
  }

  discountValueHint : string = ""
  setDiscountValueHint() {
    if (this.coupon.discount < 100) {
      this.discountValueHint = `${(this.coupon.discount / 10).toFixed(1)}折`
    }
  }

}

export class Coupon {
  coupon_batch_id : number
  object_id : number
  mode : number
  threshold : number
  reduce : number
  discount : number
  quantity : number
  got : number
  used : number
  constructor(
    coupon_batch_id : number,
    object_id : number,
    mode : number,
    threshold : number,
    reduce : number,
    discount : number,
    quantity : number,
    got : number,
    used : number
  ) {
    this.coupon_batch_id = coupon_batch_id
    this.object_id = object_id
    this.mode = mode
    this.threshold = threshold
    this.reduce = reduce
    this.discount = discount
    this.quantity = quantity
    this.got = got
    this.used = used
  }
}
export class CouponBatch {
  operator_id : string
  coupon_type : number
  batch : string
  name : string
  quantity : number
  got : number
  used : number
  valided_at : string
  expired_at : string
  remark : string
  constructor(
    operator_id : string,
    coupon_type : number,
    batch : string,
    name : string,
    quantity : number,
    got : number,
    used : number,
    valided_at : string,
    expired_at : string,
    remark : string
  ) {
    this.operator_id = operator_id
    this.coupon_type = coupon_type
    this.batch = batch
    this.name = name
    this.quantity = quantity
    this.got = got
    this.used = used
    this.valided_at = valided_at
    this.expired_at = expired_at
    this.remark = remark
  }
}
export class CouponTicket {
  code : string
  coupon_id : number
  created_at : string
  deleted : boolean
  device_id : string
  object_id : number
  order_id : string
  updated_at : string
  user_id : string
  constructor(
    code : string,
    coupon_id : number,
    created_at : string,
    deleted : boolean,
    device_id : string,
    object_id : number,
    order_id : string,
    updated_at : string,
    user_id : string) {
    this.code = code
    this.coupon_id = coupon_id
    this.created_at = created_at
    this.deleted = deleted
    this.device_id = device_id
    this.object_id = object_id
    this.order_id = order_id
    this.updated_at = updated_at
    this.user_id = user_id
  }
}